<template>
  <dialog-editor ref="dialog" :width="50"></dialog-editor>
</template>

<script>
  import DialogEditor from '@/components/DialogEditor'
  import dialogMixins from '@/utils/commonDialogMixins'
  import {mRequest} from '@/utils/request'

  export default {
    mixins: [dialogMixins],
    components: {DialogEditor},
    data() {
      return {
        dataFormConfig: {
          id: {
            hidden: true
          },
          qualityType: {
            hidden: true
          },
          qualityFilePath: {
            label: '抽检报告',
            type: 'uploadImage',
            imageType: 'uploadProductImage'
          },
          qualityRemark: {
            label: '备注',
            inputType: 'textarea',
            placeholder: '请输入备注'
          },
          qualityStatus: {
            label: '质检状态',
            type: 'radio',
            radioBorder: false,
            radioList: [
              {text: '挑选', label: 17},
              {text: '合格', label: 18},
              {text: '不合格', label: 19},
              {text: '特采', label: 20}
            ],
            default: 18
          },
        }
      }
    },
    methods: {

      init(id, property, cb) {
        this.dataForm.id = id || 0
        this.$refs.dialog.initDialog({
          dataForm: this.dataForm,
          config: this.dataFormConfig,
          saveApi: 'qualityApi/saveQualityApprovalInfo',
          updateApi: 'qualityApi/saveQualityApprovalInfo',
          objectName: 'qualityApprovalInfo',
          submitCallback: cb
        })

        this.$nextTick(() => {
          if (!this.R.isNil(property)) {
            Object.keys(property).forEach((key) => {
              this.dataForm[key] = property[key]
            })
          }
        })
      }
    }
  }
</script>

<!--<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="采购类型" prop="purchaseType">
      <el-input v-model="dataForm.purchaseType" placeholder="采购类型"></el-input>
    </el-form-item>
    <el-form-item label="模具ID" prop="purchaseModelId">
      <el-input v-model="dataForm.purchaseModelId" placeholder="模具ID"></el-input>
    </el-form-item>
    <el-form-item label="配件ID" prop="purchasePartId">
      <el-input v-model="dataForm.purchasePartId" placeholder="配件ID"></el-input>
    </el-form-item>
    <el-form-item label="深加工质检" prop="deepOrderId">
      <el-input v-model="dataForm.deepOrderId" placeholder="深加工质检"></el-input>
    </el-form-item>
    <el-form-item label="合格证路径" prop="qualityFilePath">
      <el-input v-model="dataForm.qualityFilePath" placeholder="合格证路径"></el-input>
    </el-form-item>
    <el-form-item label="质检合格数量" prop="qualifiedNumber">
      <el-input v-model="dataForm.qualifiedNumber" placeholder="质检合格数量"></el-input>
    </el-form-item>
    <el-form-item label="不合格数量" prop="unqualifiedNumber">
      <el-input v-model="dataForm.unqualifiedNumber" placeholder="不合格数量"></el-input>
    </el-form-item>
    <el-form-item label="质检状态" prop="qualityStatus">
      <el-input v-model="dataForm.qualityStatus" placeholder="质检状态"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          purchaseType: '',
          purchaseModelId: '',
          purchasePartId: '',
          deepOrderId: '',
          qualityFilePath: '',
          qualifiedNumber: '',
          unqualifiedNumber: '',
          qualityStatus: '',
          remark: '',
          createTime: '',
          createUser: '',
          updateTime: '',
          updateUser: ''
        },
        dataRule: {
          purchaseType: [
            { required: true, message: '采购类型不能为空', trigger: 'blur' }
          ],
          purchaseModelId: [
            { required: true, message: '模具ID不能为空', trigger: 'blur' }
          ],
          purchasePartId: [
            { required: true, message: '配件ID不能为空', trigger: 'blur' }
          ],
          deepOrderId: [
            { required: true, message: '深加工质检不能为空', trigger: 'blur' }
          ],
          qualityFilePath: [
            { required: true, message: '合格证路径不能为空', trigger: 'blur' }
          ],
          qualifiedNumber: [
            { required: true, message: '质检合格数量不能为空', trigger: 'blur' }
          ],
          unqualifiedNumber: [
            { required: true, message: '不合格数量不能为空', trigger: 'blur' }
          ],
          qualityStatus: [
            { required: true, message: '质检状态不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          createUser: [
            { required: true, message: '创建者不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新日期不能为空', trigger: 'blur' }
          ],
          updateUser: [
            { required: true, message: '更新者不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/quality/qualityapprovalinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.purchaseType = data.qualityApprovalInfo.purchaseType
                this.dataForm.purchaseModelId = data.qualityApprovalInfo.purchaseModelId
                this.dataForm.purchasePartId = data.qualityApprovalInfo.purchasePartId
                this.dataForm.deepOrderId = data.qualityApprovalInfo.deepOrderId
                this.dataForm.qualityFilePath = data.qualityApprovalInfo.qualityFilePath
                this.dataForm.qualifiedNumber = data.qualityApprovalInfo.qualifiedNumber
                this.dataForm.unqualifiedNumber = data.qualityApprovalInfo.unqualifiedNumber
                this.dataForm.qualityStatus = data.qualityApprovalInfo.qualityStatus
                this.dataForm.remark = data.qualityApprovalInfo.remark
                this.dataForm.createTime = data.qualityApprovalInfo.createTime
                this.dataForm.createUser = data.qualityApprovalInfo.createUser
                this.dataForm.updateTime = data.qualityApprovalInfo.updateTime
                this.dataForm.updateUser = data.qualityApprovalInfo.updateUser
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/quality/qualityapprovalinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'purchaseType': this.dataForm.purchaseType,
                'purchaseModelId': this.dataForm.purchaseModelId,
                'purchasePartId': this.dataForm.purchasePartId,
                'deepOrderId': this.dataForm.deepOrderId,
                'qualityFilePath': this.dataForm.qualityFilePath,
                'qualifiedNumber': this.dataForm.qualifiedNumber,
                'unqualifiedNumber': this.dataForm.unqualifiedNumber,
                'qualityStatus': this.dataForm.qualityStatus,
                'remark': this.dataForm.remark,
                'createTime': this.dataForm.createTime,
                'createUser': this.dataForm.createUser,
                'updateTime': this.dataForm.updateTime,
                'updateUser': this.dataForm.updateUser
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>-->
